package config;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.setting.Setting;
import lombok.Data;

import java.io.File;

/**
 * @Description PACKAGE_NAME
 * @Author zhengzetao
 * @Date 2022/9/16 15:55
 */
@Data
public abstract class Config {

    private String group;

    private Setting setting;

    private Config(){}

    public Config(String configGroup) {
        Setting config = new Setting("conf");
        File configFile = new File(config.getStr("CONFIG_PATH"));
        setting = new Setting(configFile, CharsetUtil.CHARSET_UTF_8, true);
        this.group = configGroup;
    }

    public String getStr(String key){
        return setting.getByGroup(key,group);
    }

    public String getStr(String key,String defaultValue){
        return setting.getStr(key,group,defaultValue);
    }

    public String[] getStrings(String key){
        return setting.getStrings(key,group);
    }

    public Boolean getBoolDefaultFalse(String key){
        return getBool(key,false);
    }

    public Boolean getBool(String key,boolean defaultValue){
        return setting.getBool(key,this.group,defaultValue);
    }

    public boolean containsKey(String key){
        return setting.containsKey(group,key);
    }

}
